<?php
/**
 * User: Hunman
 * Date: 20.07.13
 * Time: 10:04
 */

class Controller_Conrtoller {

    protected $view;
    protected $template;

    public $filters;
    public $productOnPage = 21;
    public $countPage;

    protected $ordreNamePrice;
    protected $limitBegin;
    protected $limitCount;
    protected $uriNoFilter;

    private
    function getData()
    {

        $cartInfo = unserialize($_COOKIE['cartInfo']);

        $view = new View_View();

        $view->template  = $this->template;
        $view->data      = $this->view;
        $view->countPage = $this->countPage;

		$view->cartInfo  = $cartInfo;
        $view->smallCart = View_View::prepareSmallCartInfo($cartInfo);
        $view->ordreNamePrice = $this->ordreNamePrice;
        $view->limitBegin = $this->limitBegin;
        $view->limitCount = $this->limitCount;
        $view->uriNoFilter = $this->uriNoFilter;
        $view->view();
    }

    protected
    function render($template)
    {
        $this->template = $template;
        $this->getData();
    }

    protected function filter($filter)
    {
        preg_match_all("/(\w+?):(\d+)/", $filter, $filterVar);
        foreach ($filterVar[1] as $key => $value)
        {
            $filterArray[$value] = $filterVar[2][$key];
        }

        return $this->getDefaultOrderBy($filterArray);
    }
    protected function getDefaultOrderBy($OrderBy)
    {
        if(!$OrderBy["oNP"])
        {
            $OrderBy["oNP"]=0;
        }
        if(!$OrderBy["lB"])
        {
            $OrderBy["lB"]=1;
        }
        if(!$OrderBy["lC"])
        {
            $OrderBy["lC"]=12;
        }

        $this->filters = $OrderBy;

        return $OrderBy;
    }
}